﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;

public partial class Admin : System.Web.UI.Page
{
    public string GetTime {
        get {
            return dlHour.SelectedValue + ":" + this.ddlMinutes.SelectedValue;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) {
            for (int index = 1; index <= 24; index++) {
                dlHour.Items.Add(index.ToString("00"));
            }
            for (int index = 0; index <= 59; index++)
            {
                this.ddlMinutes.Items.Add(index.ToString("00"));
            }
        }
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        txtFlightName.Text = "";
        txtSchedule.Text = "";
        txtTotalSeat.Text = "";
        txtFlightName.Focus();
    }
    ConnectUnit conn = new ConnectUnit("localhost", "sa", "sa", "FlyWaySystem");
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        String flightName = "FMW " + txtFlightName.Text;
        String origin = ddlOrigin.Text;
        String destination = ddlDestination.Text;
        String schedule = txtSchedule.Text;
        String totalSeat = txtTotalSeat.Text;
        String time = GetTime;
        String Class = ddlClass.Text;
        if (flightName.Length < 4 || totalSeat == "" || schedule=="") {
            MessageBox.Show("Bạn cần phải nhập đầy đủ thông tin cho chuyến bay!");
        }
        else{
            Dictionary<string, object> valueInsert = new Dictionary<string, object>();
            valueInsert.Add("FlightName", flightName);
            valueInsert.Add("Origin", origin);
            valueInsert.Add("Destination", destination);
            valueInsert.Add("Schedule", schedule);
            valueInsert.Add("TotalSeat", totalSeat);
            valueInsert.Add("AvailableSeat", totalSeat);
            valueInsert.Add("Class", Class);
            valueInsert.Add("FlightTime", time);
            Boolean x = conn.Insert("FlightInformation", valueInsert);
            if(!x){
                MessageBox.Show("Lưu dữ liệu thất bại, bạn phải kiểm tra lại kết nối với CSDL");
            }
        }
    }
}
